﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <link href="../CSS/style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.pager.js" type="text/javascript"></script>
    <script type="text/javascript">
        //添加一个角色
        function showAdd() {
            $.showModalDialog("userManagerAdd.htm", null, 600, 210, function (r) {
                Load();
            })
        }
        //修改一个角色
        function showEdit(id) {
            $.showModalDialog("userManagerEdit.htm", { id: id }, 600, 400, function (r) {
                //判断有没有修改成功
                if (r) {
                    //修改成功，刷新列表
                    Load();
                }
            })
        }
        //删除一个角色
        function showDelete(id) {
            //询问
            if (!confirm("确认删除吗？")) return;
            $.ajax({
                url: "userManager.asmx/DeleteUser",
                type: "post",
                data: JSON.stringify({ id: parseInt(id) }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    alert(obj.d ? "删除成功" : "删除失败");
                    //刷新
                    Load();
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        }
        function xiao() {
            $("#tab tr:gt(0)").live("click", function () {

                $("#dataDiv .dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "red");

            });
        }
        $(function () {
            Load();
            xiao();
        });
        function Load() {

            $("#pageDiv").empty().pager2("userManager.asmx/paging", {}, function (data) {
                
                //展示查询的结果
                $("#tab tr:gt(0)").remove();
                var tab = $("#tab").get(0);
                
                for (var i = 0; i < data.length; i++) {
                    var tr = tab.insertRow(-1);

                    tr.insertCell(-1).innerHTML = data[i].UserID;
                    tr.insertCell(-1).innerHTML = data[i].UserLName;
                    tr.insertCell(-1).innerHTML = data[i].UserName;
                    tr.insertCell(-1).innerHTML = data[i].RoleName;
                    tr.insertCell(-1).innerHTML = "<img title='修改' src='../images/33.gif' onclick='showEdit(" + data[i].UserID + ");' /><img title='删除' src='../images/11.gif' onclick='showDelete(" + data[i].UserID + ");' />";
                }
            });
        }
    </script>
</head>
<body>
<div id="desDiv">
    <span>用户管理</span><br />
    创建和维护系统中的登陆用户
</div>
<div id="dataDiv">
    <div id="headDiv">
        <img src="../images/22.gif" />&nbsp;&nbsp;<a href="javascript:showAdd()">新建</a>
    </div>
    <table class="dataTable" id="tab">
        <tr>
            <th width="100">用户编号</th>
            <th>用户名</th>
            <th>用户姓名</th>
            <th>所属角色</th>
            <th>操作</th>
        </tr>
    </table>
    <div id="pageDiv">
     
    </div>
</div>
</body>
</html>
